package com.guanyong.dao;

import com.guanyong.model.VideoBuyLogModel;
import org.apache.ibatis.annotations.*;

import java.util.Date;
import java.util.List;

/**
 * Created by mxk on 2017/5/26.
 * 视频购买日志
 *
 */
public interface IVideoBuyLogDaoMapper {

    @Insert("INSERT INTO t_ad_videobuylog" +
            "(f_id,f_billid,f_billtype,f_billname,f_userid,f_classtype,f_objectid," +
            "f_money,f_offday,f_ip,f_apptype) VALUES"+
            "(#{fId},#{fBillid},#{fBilltype},#{fBillname},#{fUserid}," +
            "#{fClasstype},#{fObjectid},#{fMoney},#{fOffday},#{fIp},#{fApptype})")
    int insert(VideoBuyLogModel record);

    @Update("update t_ad_videobuylog  set f_offday=DATE_ADD(NOW(),INTERVAL #{day} DAY),f_state=1 " +
            " where f_id=#{id}")
    int UpdateSate(@Param("id") String id,@Param("day") Integer day);

    List<VideoBuyLogModel> SelectVideoBuyLogList(
            @Param("buylogModel") VideoBuyLogModel buylogModel,
            @Param("isoff") Integer isoff,
            @Param("btime") String btime,
            @Param("etime") String etime,
            @Param("offset") Integer offset,
            @Param("limit") Integer limit
    );

    Integer SelectVideoBuyLogListCount(
            @Param("buylogModel") VideoBuyLogModel buylogModel,
            @Param("isoff") Integer isoff,
            @Param("btime") String btime,
            @Param("etime") String etime
    );

    @Select("SELECT 1 FROM t_ad_videobuylog WHERE f_userid=#{userid} AND f_objectid=#{objectId} " +
            "AND f_classtype=#{classType} AND f_offday>=CURDATE()")
    Integer CheckUserIsVip(@Param("userid") String userid,
                           @Param("objectId") String objectId,
                           @Param("classType") Integer classType);


}
